<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
        <br>
        <c:choose>
            <c:when test="${edit==null}">
                   <div id="form">
                    <b>Dodaj nową kategorie:</b><br>
                    <form:form method="Post" commandName="addCategory">
                        <form:hidden path="idc"/>
                        <table>
                            <tr><td class="label">Nazwa nowej kategorii:</td><td><form:input path="newCat"/></td></tr>
                            <tr><td class="label">Kategoria nadrzędna:</td><td>
                               <form:select path="category">
                                   <form:option value="0" label="Kategoria główna"/>
                                   <c:forEach items="${categoryList}" var="cat">
                                            <form:option value="${cat.idcategory}" label="${cat.categoryname}"/>
                                   </c:forEach>
                               </form:select></td></tr>
                                <tr><td></td><td><input type="submit" value="Dodaj"/></td></tr>
                        </table>
       
                      </form:form>
                    </div>

            </c:when>
                <c:otherwise>
                    <div id="form">
                    <b>Edytuj kategorie:</b><br>
                    <form:form method="Post" commandName="editCategory">
                        <table>
                            <tr><td>Nazwa kategorii:</td><td><form:input path="newCat" value="${categoryEdit.categoryname}"/></td></tr>
                            <tr><td>Kategoria nadrzędna:</td><td>
                               <form:hidden path="idc"/>
                               <form:select path="category">
                                   <form:option value="0" label="Kategoria główna"/>

                                   <c:forEach items="${categoryList}" var="cat">
                                       <c:choose>
                                           <c:when test="${categoryEdit.category.idcategory==cat.idcategory}">
                                               <form:option value="${cat.idcategory}" label="${cat.categoryname}" selected="selected"/>
                                           </c:when>
                                           <c:otherwise>
                                               <form:option value="${cat.idcategory}" label="${cat.categoryname}"/>
                                           </c:otherwise>
                                       </c:choose>
                                   </c:forEach>
                               </form:select></td></tr>
                                <tr><td></td><td><input type="submit" value="Zapisz"/></td></tr>
                        </table>
                      </form:form>
                    </div>
                </c:otherwise>
        </c:choose>
        <br>
        Przeglądaj dostępne kategorie produktów:
        <table>
        <tr><td width="400" class="header"><b>Nazwa kategorii</b></td><td class="header"><b>Edytuj</b></td><td class="header"><b>Usuń</b></td></tr>
            <c:forEach items="${categoryList}" var="cat">
                 <tr><td width="400" class="main_cat">${cat.categoryname}<a href="categories.htm?op=show&id=${cat.idcategory}" style="float:right"><img src="../img/icons/show.png" border="0"/></a></td><td><a href="categories.htm?op=edit&id=${cat.idcategory}"><img src="../img/icons/edit1.png" border="0"/></a></td><td><a href="categories.htm?op=delete&id=${cat.idcategory}"><img src="../img/icons/remove.png" border="0"/></a></td></tr>
                <c:if test="${cat.idcategory==categoryShownNr}">
                    <c:forEach items="${categoryShown}" var="cat2">
                        <tr><td width="400" class="sub_cat">${cat2.categoryname}</td><td><a href="categories.htm?op=edit&id=${cat2.idcategory}"><img src="../img/icons/edit1.png" border="0"/></a></td><td><a href="categories.htm?op=delete&id=${cat2.idcategory}"><img src="../img/icons/remove.png" border="0"/></a></td></tr>
                    </c:forEach>
                </c:if>
            </c:forEach>
        </table>
